package dao

import (
	"github.com/tianjigames/fairy/pojo"
	"github.com/topfreegames/pitaya/logger"
	"sync"
)
var (
	GuidDataDao     *guidDataDao
	guidDataDaoOnce sync.Once
)

type guidDataDao struct {
	BaseDao
}

func NewGuidDao() *guidDataDao {
	guidDataDaoOnce.Do(func() {
		GuidDataDao = &guidDataDao{}
	})
	return GuidDataDao
}

func (g *guidDataDao) GetGuidDataById(id int) (*pojo.GuidData,error) {
	guiData := &pojo.GuidData{}
	result,err := g.enginer.Where("id=?",id).Get(guiData)
	if err != nil {
		logger.Log.Errorf("GetGuidDataByDes failed,error:%s",err.Error())
		return nil,err
	}

	if !result {
		return nil,nil
	}

	return guiData,nil
}

func (g *guidDataDao) SaveGuidData(guidData *pojo.GuidData) error {
	_,err := g.enginer.ID(guidData.Id).Update(guidData)
	if err != nil {
		logger.Log.Errorf("update failed,error:%s",err.Error())
		return err
	}
	return nil
}